home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 April: Mac OS SDK / Dev.CD Apr 97 SDK1.toast / Development Kits (Disc 1) / AppleScript / Goodies / Scripting Additions / XCMD Adapter / XCMD Adapter Read Me next >
Encoding:
Text File  |  1993-12-08  |  4.2 KB  |  64 lines  |  [TEXT/ttxt]

  1. The XCMD Adapter Scripting Addition allows you to use XCMD/XFCN as Scripting Additions. This is an experimental version and has not been tested. However most of the code comes from the AEXCMDShell program which has been in use for some time. 
  2.  
  3. To call the XCMD, the Scripting Addition must be first loaded, then the XCMD, so this is not the most efficient way to do thing. However this gives you a quick and dirty shortcut to access a lot of the functions from AppleScript.
  4.  
  5. Not all XCMD callbacks are implemented. Try each individual XCMD to see if it works. The XCMD parameters need to follow the convention that parameters are by position and empty strings means missing optional parameter. In general, if the XCMD can work in AEXCMDShell, then it can be used as an Scripting Addition unless it needs to use the GetGlobal, SetGlobal or SendHCEvents callbacks. Furthermore, since most XCMD are written before system 7 and therefore do not to call AEInteractWithUser even when it is necessary, this may introduce  inappropriate layer switching. 
  6.  
  7. Since this is a prototype meant for the developer, we shall assume that you can use ResEdit and Aete Editor to edit the resource. We shall assume that you will use ResEdit to put all the XCMDs and their resource into the Scripting Addition. Then you need to edit the aete resource to tell the world about the XCMDs you have in the Scripting Addition. Each XCMD or XFCN must have a event class of ‘XCMD’. The Apple Event parameters must be in the same order as the XCMD parameters. For every XCMD you also have to generate a XINF resource which summarize the aete information for that particular XCMD. The ResEdit template is in the OSAX. The name of the XINF resource should be the same as the event ID for the XCMD. The information is mainly the keyword, dataType and delimiter for each parameter. The delimiter is “A” if the parameter is not a list. If it is a list, the delimiter is the characters that separates one item of the list from each other. Usually it is “,” or carriage return, but it can also be “|”, null or any other character you choose.
  8.  
  9. In future we shall release a new version AEXCMDShell that can generate the Scripting Addition without going through this. Look for it in AppleLink or the Developer CD.
  10.  
  11. We have included a XCMD and a XFCN as an example. The XCMD is the familiar Flash XCMD, it takes a direct parameter of type short integer. The XFCN let you determine the coordinate of a rectangle on the screen. You will use the cursor to pick the two opposite corner of a rectangle, and then a “qdrt” data type will be returned.
  12.  
  13. We also export two commands which are used internally in the Scripting Addition. They are TextToList and ListToText.
  14.  
  15. TextToList theText [delimiter theDelimiter] [dataType theDataType]
  16.  
  17. TextToList “1, 2, 3” returns {“1”, “2”, “3”}
  18. TextToList “1, 2, 3” datatype integer returns {1, 2, 3}
  19. TextToList “1, 2, 3” delimiter “|” datatype integer returns {1, 2, 3}
  20. TextToList “1, 2a3, 3” datatype integer fails
  21.  
  22. ListToText theList [delimiter theDelimiter]
  23.  
  24. ListToText {1, 2, 3} returns “1,2,3”
  25. ListToText {1, 2, 3} delimiter “ ” returns “1 2 3”
  26. ListToText {1, {2, 3, 4} 5} fails
  27.  
  28. Here is an example script that let you mimic the chooser to choose your default printer .
  29.  
  30. The XCMD used are
  31.  
  32. ChoosePrinter from Chooser 1.5 by Frédéric RINALDI.
  33. DeviceList from Chooser 1.5 by Frédéric RINALDI. 
  34. CurrPrinter from Chooser 1.5 by Frédéric RINALDI.
  35. Sort by Gary Bond.
  36. ShowList from HyperCard PowerTools.
  37.  
  38. The script is
  39.  
  40. copy 0 to dftprtindex
  41. copy (DeviceList drivername "LaserWriter") to prtlist
  42. copy (Sort prtlist) to prtlist
  43. copy (CurrPrinter) to curprint
  44. if first item of curprint = "LaserWriter" then
  45.     copy item 2 of curprint to curprint
  46.     copy 0 to i
  47.     repeat with x in prtlist
  48.         copy i + 1 to i
  49.         if x = curprint then
  50.             copy i to dftprtindex
  51.         end if
  52.     end repeat
  53. end if
  54. copy (ShowList prtlist prompt "Choose a printer" buttons {"OK", "Cancel"} hilitedline dftprtindex typingselect true multiselect false) as list to choice
  55. if (number of items in choice) = 2 then
  56.     if first item of choice = "OK" then
  57.         copy (item 2 of choice) as integer to prtindex
  58.         if dftprtindex ≠ prtindex then
  59.             copy item prtindex of prtlist to prtname
  60.             ChoosePrinter drivername "LaserWriter" printername prtname
  61.         end if
  62.     end if
  63. end if
  64.